package name.sraynal.msgdispatcher.controller;

import java.util.HashSet;
import java.util.Set;

import name.sraynal.msgdispatcher.event.Event;
import name.sraynal.msgdispatcher.model.DispatcherModel;
import name.sraynal.msgdispatcher.view.EndView;
import name.sraynal.msgdispatcher.view.FilesView;
import name.sraynal.msgdispatcher.view.TextView;

public class ApplicationController extends Controller {
	
	private FileController fileController;
	private TextController textController;
	private TextView textView;
	private FilesView filesView;
	private EndView endView;
	
	public ApplicationController(DispatcherModel model) {
		super(model);
		Set<Controller> controllers = new HashSet<Controller>();
		
		this.fileController = new FileController(this.model);
		this.textController = new TextController(this.model);
		
		controllers.removeAll(null);
		controllers.add(textController);
		this.textView = new TextView(controllers);
		this.textController.setTextView(this.textView);
		
		controllers.removeAll(null);
		controllers.add(this.fileController);
		controllers.add(this.textController);
		this.filesView = new FilesView(controllers);
		this.fileController.setFilesView(this.filesView);
		this.textController.setFilesView(this.filesView);
		
		controllers.removeAll(null);
		controllers.add(this.fileController);
		controllers.add(this);
		this.endView = new EndView(controllers);
		this.fileController.setEndView(this.endView);
		
	}

	@Override
	public void sendEvent(Event event) {
		if (event.getType() == Event.START_APP) {
			displayView(this.textView);
		} else if (event.getType() == Event.END_APP) {
			
		}
	}

}
